import java.util.Stack;

public class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> minstack;

    public MinStack() {
        this.stack = new Stack<>();
        this.minstack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if (minstack.empty()) {
            minstack.push(val);
        } else {
            if (minstack.peek() >= val) {
                minstack.push(val);
            }
        }
    }

    public void pop() {
        if(!stack.empty()){
            int x = stack.pop();
            if (x == minstack.peek()) {
                minstack.pop();
            }
        }

    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minstack.peek();
    }
}